#ifndef GLYPHCACHE_H
#define GLYPHCACHE_H
#include "Glyph.h"
#include "FontFace.h"
#include "map"
namespace FT
{
template <class T>
class GlyphCache
{
public:
    GlyphCache(FontFace &fontFace) : fontFace(fontFace)
    {
    }
    ~GlyphCache()
    {
        for(std::map<ulong,T*>::iterator it = cache.begin(); it != cache.end(); it++)
        {
            BaseGlyph *toDelete  = (*it).second;
            delete toDelete;
        }
    }
    T* getGlyph(ulong codePoint)
    {
        if(cache.find(codePoint) == cache.end())
            cache[codePoint] = fontFace.createGlyph<T>(codePoint);
        return cache[codePoint];
    }
private:
    std::map<ulong,T*> cache;
    FontFace &fontFace;
};
}
#endif // GLYPHCACHE_H
